﻿using Raven;
using UnityEngine;

public class MeshFactory
{
    public static Mesh LineMesh(Vector3 a, Vector3 b, Color color)
    {
        VertexBuffer vb = VertexBuffer.Begin();
        vb.vertexColor = color;
        vb.AddLine(a, b, Vector3.forward);
        Mesh mesh = vb.ToMesh();
        vb.End();
        return mesh;
    }

    public static Mesh EllipseMesh(Vector3 center, float radius, float radian, Color color)
    {
        VertexBuffer vb = VertexBuffer.Begin();
        vb.vertexColor = color;
        vb.AddEllipse(center, radius, radian);

        Mesh mesh = vb.ToMesh();
        vb.End();
        return mesh;
    }
    
    public static Mesh EllipseMesh(Vector3 center, float radius, Color color)
    {
        VertexBuffer vb = VertexBuffer.Begin();
        vb.vertexColor = color;
        vb.AddEllipse(center, radius, 2 * Mathf.PI);

        Mesh mesh = vb.ToMesh();
        vb.End();
        return mesh;
    }


    public static Mesh CycleMesh(Vector3 center, float radius, Color color)
    {
        VertexBuffer vb = VertexBuffer.Begin();
        vb.vertexColor = color;
        vb.AddCycle(center, radius);
        Mesh mesh = vb.ToMesh();
        vb.End();
        return mesh;
    }

    public static Mesh BotShape()
    {
        VertexBuffer vb = VertexBuffer.Begin();

        float radius = (float)Constants.Bot_BRadius;
        Vector3[] points =
        {
            new Vector3(-3, 8),
            new Vector3(3, 10),
            new Vector3(3, -10),
            new Vector3(-3, -8)
        };

        for (int i = 0; i < points.Length - 1; i++)
        {
            vb.AddLine(points[i], points[i + 1], Vector3.forward, Color.blue);
        }

        vb.AddLine(points[points.Length - 1], points[0], Vector3.forward, Color.blue);

        vb.AddEllipse(Vector3.zero, radius, new Color(133 / 255.0f, 90 / 255.0f, 0));
        Mesh mesh = vb.ToMesh();
        vb.End();
        return mesh;
    }

    public static Mesh CloseShape(Vector3[] points, Color color)
    {
        VertexBuffer vb = VertexBuffer.Begin();

        for (int i = 0; i < points.Length - 1; i++)
        {
            vb.AddLine(points[i], points[i + 1], Vector3.forward, color);
        }

        vb.AddLine(points[points.Length - 1], points[0], Vector3.forward, color);

        Mesh mesh = vb.ToMesh();
        vb.End();
        return mesh;
    }
}